<template>
	<view style="width: 100%;margin: auto;">
		<lodings v-if="show"></lodings>
		<web-view :webview-styles="webviewStyles" :src="activity"></web-view>
	</view>
</template>

<script>
import lodings from '../../components/loding_zdy.vue';
var that;

export default {
	components: {
		lodings
	},
	data() {
		return {
			show:false,
			userId: '',
			activity: '',
			webviewStyles: {
				progress: {
					color: '#FF3333'
				}
			}
		};
	},
	onShow() {
		var that=this;
		that.token = uni.getStorageSync('token');
		//判断是否登录
		if (!that.token) {
			uni.hideShareMenu();
		}else{
			uni.showShareMenu();
		}
		this.showActivity();
	},
	onLoad(option) {
		var parentId = option.parentId;
		if (parentId) {
			uni.setStorageSync('parentId', parentId);
			uni.navigateTo({
				url:'../login/login'
			})
			return false;
		}
		if (!uni.getStorageSync('token')) {
			this.islogin();
			return;
		}
		var userInfo = JSON.parse(uni.getStorageSync('userinfo'));
		this.userId = userInfo.userId;
		
	},
	onReady() {},
	methods: {
		// 登录判断
		islogin() {
			uni.showModal({
				title: '登录提示',
				content: '该功能需要登录后使用。',
				confirmText: '去登录',
				success: function(res) {
					if (res.confirm) {
						uni.navigateTo({
							url: '/pages/login/login'
						});
					} else if (res.cancel) {
					}
				}
			});
			return;
		},
		onShareAppMessage(res) {
			if (res.from === 'button') {
				// 来自页面内分享按钮
			}
			let opts = {
				way: true, //true JSON请求；false 表单请求
				method: 'post',
				url: 'common/insertShareLog'
			};
			let data = {};
			this.http.httpTokenRequest(opts, data).then(res => {
				//分享日志，不需要处理
			});
			return {
				title: '必到清洗季，新客享福利',
				// imageUrl:'https://beedao.oss-cn-beijing.aliyuncs.com/cca1cf07545140e6b44c42f1c9b861d8.png',
				 path:'/pages/login/login?id='+this.userId+"&jumpType="+3
				// path: '/pages/home/home?type=' + 2 + '&id=' + this.userId
			};
		},
		// 分享到朋友圈
		// onShareTimeline() {
		// 	let opts = {
		// 		way: true, //true JSON请求；false 表单请求
		// 		method: 'post',
		// 		url: 'common/insertShareLog'
		// 	};
		// 	let data = {};
		// 	this.http.httpTokenRequest(opts, data).then(res => {
		// 		//分享日志，不需要处理
		// 	});
		// 	return {
		// 		title: '必到清洗季，新客享福利',
		// 		// imageUrl:'https://beedao.oss-cn-beijing.aliyuncs.com/cca1cf07545140e6b44c42f1c9b861d8.png',
		// 		query:'parentId='+this.userId
		// 		// path: '/pages/home/home?type=' + 2 + '&id=' + this.userId
		// 	};
		// },
		// 活动
		showActivity: function() {
			this.show=true;
			let opts = {
				way: true, //true JSON请求；false 表单请求
				method: 'post',
				url: 'other/getActivityAddress'
			};
			let data = {};
			this.http.httpTokenRequest(opts, data).then(res => {
				//打印请求返回的数据
				if (res.code == '200') {
					this.show=false;
					this.activity = res.data + '?t=' +Math.ceil(Math.random() * 1000);
					console.log(this.activity)
				} else {
					this.show=false;
					// this.$refs.uToast.show({
					// 	title: res.message,
					// 	type: 'error'
					// });
				}
			});
		}
	}
};
</script>

<style></style>
